﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using VSDBM.Code.dao;
using VSDBM.Code.dto;


namespace VSDBM.Code.functions
{
    public class Login
    {
        public static Boolean login(String user, String password)
        {

            DataSet ds = UserDAO.select(false, " WHERE login = '"+user+"'  and password = '"+Encryption.CalculateMD5Hash(password)+"' and status = 1", "");
            try
            {
                if (ds.Tables.Count != 0)
                {
                    if (ds != null && ds.Tables[0].Rows.Count == 1)
                    {
                        HttpContext.Current.Session["usuariologado"] = UserDAO.DStoList(ds)[0];
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                   return false;
                }
            }
            catch (Exception e)
            {
                throw e;
            }

        }
    }
}